﻿Imports System.Web
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services
Imports System.Web.Script.Services
Imports System.Web.Services.Protocols
Imports VSModel
Imports System.Data.Objects
Imports Newtonsoft.Json

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class ProductServices
    Inherits System.Web.Services.WebService
   

    <WebMethod()> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Function NewsProduct(ByVal strCateId As String) As String
        Dim json As String
        '  Dim deserializedProduct as 
        Dim strConnect As String = ""
        Using data As New VSEntities
            'Load du lieu ung voi ky tu nhap vao  Where p.CateID = strCateId 
            'select tat ca cat
            Dim a = (From r In data.uspSelectSubCate(strCateId) Select r.CateID).ToArray

            Dim pro = (From p In data.Products Where (a.Contains(p.CateID) Or p.CateID = strCateId) And p.StatusId = 3 Select p.CateID, p.ProductId, p.ImagePreview, p.Title, p.QueryString).Take(8).ToList

            'format json
            json = JsonConvert.SerializeObject(pro)
           
        End Using

    

        Return json
    End Function
End Class